/*
 * @Description: 路由守卫
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2024-04-28
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2024-05-16
 */

import { message } from 'ant-design-vue'
import { Router } from 'vue-router'

import { MESSAGE_KEY } from '/@/enums/commonEnum'
import { RouterPathEnum } from '/@/enums/routerEnum'
import { router } from '/@/router'

/** 路由白名单 */
export const whiteNameList: string[] = [RouterPathEnum.LOGIN, RouterPathEnum.REGISTER, RouterPathEnum.AGREEMENT, RouterPathEnum.HOME, RouterPathEnum.FORBIDDEN, RouterPathEnum.NOT_FOUND, RouterPathEnum.SYSTEM_ERROR]

/**
 * 校验白名单路由
 * @returns
 */
export const checkWhiteRoute = () => {
  const path = window.location.pathname.replace(`${import.meta.env.VITE_BASE_ROUTE_PATH}`, '')
  return whiteNameList.includes(path)
}

/**
 * 创建路由守卫
 */
export const createRouterGuards = (router: Router) => {
  //TODO
}

/**
 * 跳转登录
 */
export const goLogin = () =>
  message.error({
    key: MESSAGE_KEY,
    content: '登录失效，请重新登录',
    duration: 1.5,
    onClose: () => router.push(RouterPathEnum.LOGIN),
  })
